varying vec3 mynormal;
varying vec4 myvertex;

void main (void) 
{        
	vec3 eyepos = vec3(0,0,0) ; 
	vec4 _mypos = gl_ModelViewMatrix * myvertex ; 
    vec3 mypos = _mypos.xyz / _mypos.w ;
	vec4 _lightpos = vec4(0,0,-10,1);
	vec3 lightdir = normalize (- vec3(0,0,-1)) ;

	vec3 normal = normalize(gl_NormalMatrix*mynormal);
	vec3 eyedir = normalize(eyepos - mypos) ;
	vec3 lightpos = _lightpos.xyz / _lightpos.w;
	vec3 reflectdir = normalize( reflect(-lightdir, normal) );
		
	float angle = dot(eyedir, normal);

	if ( angle < 0.2 &&  angle >= 0 )
		gl_FragColor = vec4(0,0,0,1);
	else
	{
		vec4 high = vec4(1,0,0,1);
		vec4 low = vec4(0,1,0,1);

		float a = 0.3;
		float b = 0.3;

		vec4 highsurface = high + ( a * gl_FrontMaterial.diffuse );
		vec4 lowsurface = low + ( b * gl_FrontMaterial.diffuse );

		//vec4 color = ( ( 1 + max( dot(lightdir, normal), 0.0) ) / 2 ) * lowsurface 
		//			+( 1 - ( ( 1 + max( dot(lightdir, normal), 0.0) ) / 2 ) ) * highsurface; 

		vec4 color =(  dot(lightdir, normal) ) * highsurface
					+( 1 -  dot(lightdir, normal) ) * lowsurface; 
		
		gl_FragColor = color +
				vec4(1,1,1,1) * color * pow( max( dot(reflectdir, eyedir), 0.0 ), gl_FrontMaterial.shininess );

	}

}